import { ref, watchEffect } from 'vue';
export const useLocalStorage = key => {
    const storage = ref(localStorage.getItem(key))
    // 尽量在setup中使用，这样在页面销毁的时候，watchEffect也会销毁
    const stop = watchEffect(() => {
        localStorage.setItem(key, storage.value||'')
    })
    return [storage, stop]
}